/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package _4_Mapper;

import _5_DB.ConnectDB;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author DOM
 */
public class LoadCommentMapper {

    public static String load(int pid) {
        String loadcomment = "";
        try {
            ConnectDB db = new ConnectDB();
            Connection con = db.getConnection();

            CallableStatement proc = null;
            proc = con.prepareCall("{ call procLayComment(?)}");

            proc.setInt(1, pid);

            ResultSet rs = proc.executeQuery();
            while (rs.next()) {
                String content = rs.getString("contents");
                String date = rs.getString("commentdate");           
                String name = rs.getString("name");
                int uID=rs.getInt("uid");
                
                        
                        
                loadcomment += "<div class=\"noidungcomment\"><table style=\"width:580px\"> <tr> <td style=\"width:130px;text-align:center\" rowspan=\"2\"> <a href=\"AccLoadProfile?u=";
                loadcomment += uID;
                loadcomment += "\"><img style=\"width:75px;height:75px\" src=\"";
                loadcomment += ""; //avatar chua co
                loadcomment += "\" /></a><br />";
                loadcomment += "<a href=\"AccLoadProfile?u=" + uID + "\">" + name + "</a>";
                loadcomment += "</td> <td style=\"max-width:450px> <p\">";
                loadcomment += content;
                loadcomment += "</p></td> </tr> <tr> <td> ";
                loadcomment += date;
                loadcomment += "</td> </tr> </table></div><br/>";
            }
            


        } catch (SQLException ex) {
            Logger.getLogger(LoadCommentMapper.class.getName()).log(Level.SEVERE, null, ex);
        }

        return loadcomment;

    }
}
